# -*- coding: utf_8 -*-
# @Time : 2021/8/9 0009 14:46
# @Author : lyw
# @Remark : 门禁公共接口

from mxsoftpy import View
from server.common.IOTManager.Janitor.public_interface import (DataOriginConfigServer, InsertDoorServer,
                                                               InsertPersonnelServer,
                                                               InsertRecordServer, ExportExeclServer,
                                                               RecordAndPersonnelServer, GetPersonnelServer,
                                                               BatchNewRecordServer)
from index import _


class DataOriginConfig(View):
    """获取数据配置"""

    def get(self):
        """获取模板的配置"""
        host = self.request.GET["host"] if self.request.GET.get("host") else ""
        model_id = self.request.GET["model_id"] if self.request.GET.get("model_id") else ""
        result = DataOriginConfigServer().model_data_info(host, model_id)
        return _("查询成功"), result


class InsertDoor(View):
    """新增门的数据"""

    def post(self):
        """post"""
        if not self.request.POST:
            return "参数不存在..."
        return _("新增成功"), InsertDoorServer().insert_door(**self.request.POST)


class InsertRecord(View):
    """新增出入记录"""

    def post(self):
        """post"""
        if not self.request.POST:
            return "参数不存在..."
        return _("新增成功"), InsertRecordServer().insert_record(**self.request.POST)


class InsertPersonnel(View):
    """新增人员"""

    def post(self):
        """post"""
        if not self.request.POST:
            return "参数不存在..."
        return _("新增成功"), InsertPersonnelServer().insert_personnel(**self.request.POST)


class ExportReport(View):
    def get(self):
        """导出接口"""
        return _("导出成功"), ExportExeclServer().export_execl(**self.request.GET)


class RecordAndPersonnel(View):

    def post(self):
        """添加人员和记录接口"""
        return _("新增成功"), RecordAndPersonnelServer().threading_process(**self.request.POST)


class BatchNewRecord(View):

    def post(self):
        """批量新增记录"""
        return _("新增成功"), BatchNewRecordServer().threading_process(**self.request.POST)


class GetPersonnel(View):

    def get(self):
        """获取人员"""
        param = self.request.GET
        door_id = param.get("door_id")
        if not door_id:
            return "door_id参数不存在..."
        return "ok", GetPersonnelServer().get_personnel(**param)
